package leetcode.median;

/**
 * ClassName: $75_SortColors
 * Description:
 * date: 2022-02-18 21:57
 *
 * @author liyifan
 */
public class $75_SortColors {
    public void sortColors(int[] nums) {
        int p_0 = 0;
        int p_1;
        int len = nums.length;
        for (int i = 0;i < len;i++) {
            if (nums[i] == 0) {
                swap(nums, i, p_0);
                p_0++;
            }
        }
        p_1 = p_0;
        for (int i = p_0;i < len;i++) {
            if (nums[i] == 1){
                swap(nums, i, p_1);
                p_1++;
            }
        }
    }

    public void swap(int[] nums, int i, int j){
        int temp = nums[i];
        nums[i] = nums[j];
        nums[j] = temp;
    }
}
